home *** CD-ROM | disk | FTP | other *** search
- Path: qualcomm.com!usenet
- From: nabbasi@qualcomm.com (Nasser Abbasi)
- Newsgroups: comp.lang.c++
- Subject: Re: Why Do Return Values Sometimes Have '&' Appended?
- Date: 22 Feb 1996 06:53:31 GMT
- Organization: QUalcomm Inc.
- Message-ID: <4gh3tb$l7n@qualcomm.com>
- References: <4ggciv$iq1@alcor.usc.edu>
- Reply-To: x!news.be.innet.net!INbe.net!usenet
- NNTP-Posting-Host: annex-p32.qualcomm.com
- X-Newsreader: WinVN 0.90.4
-
- In article <4ggciv$iq1@alcor.usc.edu>, wawda@alcor.usc.edu (Abu Wawda) says:
- >
- >I have seen code where some of the functions are returned with the
- >reference operator (&) attached to the end. Here is an example:
- >
- >MyReturn& MyFunction(...)
- >{
- >}
- >
- >I don't understand what that does.
-
- A reference is a name for an object. so returning a refernce means
- we are returning a name for an object that sits somewhere of type
- MyReturn. So, you need to ask where is this object?
-
- One possibility is that MyFunction internally has a hidden static
- object of type MyReturn that processing is done on, then finaly
- a reference to it is returned.
-
- Or it is possible that inside MyFunction an object is created on the
- heap and a refernce is returned to it, but this can lead to memory
- leak, since client of MyFunction need to figure how to delete this object.
- Plus one do not gain much by this method compared to by just returning
- the object.
-
- Nasser
-
-
-